package com.wang.example.netty.codec.custom;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class CustomEchoClientInHandler extends SimpleChannelInboundHandler<User> {
    /**
     * 客户端读取到数据
     * @param ctx
     * @param user
     * @throws Exception
     */
    @Override
    public void channelRead0(ChannelHandlerContext ctx, User user)
            throws Exception {
        System.out.println("CustomEchoClientInHandler" + user);
    }

    /**
     * exceptionCaught()事件处理方法当出现Throwable对象才会被调用
     * 即当Netty由于IO错误或者处理器在处理事件时抛出的异常时
     * @param ctx
     * @param cause
     * @throws Exception
     */
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
            throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
